package com.dreamlin.gankio.mvvm.girl

import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.DiffUtil
import com.dreamlin.gankio.base.model.BaseViewModel
import com.dreamlin.gankio.base.ui.DiffBaseAdapter
import com.dreamlin.gankio.mvvm.home.GankEntity
import com.dreamlin.gankio.mvvm.home.feature.pageSize
import com.dreamlin.gankio.mvvm.home.other.GankEntityDiffCallback
import com.dreamlin.gankio.net.NetHelper
import com.dreamlin.gankio.net.RxHelper
import com.dreamlin.gankio.net.WrapperBean
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * <p> Title: GirlViewModel </p>
 * <p> Description: </p>
 * @author:  dreamlin
 * @date:    9/20/20
 * @version: V1.0.0
 * Created by dreamlin on 9/20/20.
 */
class GirlRepository : BaseViewModel() {
    val girlEntities = MutableLiveData<WrapperBean<List<GankEntity>>>()

    fun loadMoreData(page: Int, count: Int) {
        val subscribe = NetHelper.api.listGirls(page, count)
            .compose(RxHelper.applySchedulersWithoutLoading())
            .compose(RxHelper.handleGlobalError(this))
            .subscribe({
                girlEntities.value = it
            }, { it.printStackTrace() })
        addDisposable(subscribe)
    }

    fun refreshData() {
        val subscribe = NetHelper.api.listGirls(1, pageSize)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(RxHelper.handleGlobalError(this))
            .subscribe({
                girlEntities.value = it
            }, { it.printStackTrace() })
        addDisposable(subscribe)
    }
}